package com.activenetwork.smlite.testcase.sourcing.RFP_Basics.f01_New_RFP_Basic.f02_RFP_Name;

import javax.xml.datatype.DatatypeConfigurationException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.activenetwork.custom.uielement.UIElement;
import com.activenetwork.custom.uielement.decorate.IdentifierFactory;
import com.activenetwork.smlite.page.event.EventDetailView.EventSourceSubview;
import com.activenetwork.smlite.page.event.EventDetailView.EventSummarySubview;
import com.activenetwork.smlite.page.rfp.RfpBasicsSubview;
import com.activenetwork.smlite.page.rfp.RfpMaintenanceView.RfpSetting;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.smlite.testcase.sourcing.RfpCaseEvent;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.PageLoader;
import com.activenetwork.util.RandomString;
import com.activenetwork.util.verification.gson.FailureAssertion;
import com.activenetwork.util.verification.gson.FailurePoint;

public class RfpName001 extends BaseCase {
	
	static final Logger logger = LoggerFactory.getLogger(RfpName001.class);
	private RfpCaseEvent rfpCaseEvent;
	
	@BeforeClass(alwaysRun = true)
	public void dataSetup() throws DatatypeConfigurationException {	
		rfpCaseEvent = new RfpCaseEvent();
	}
	
	@Test
	public void Verify_RFP_name_max_length(){
		loginBusiness.login();
		
		// Create the rfp case needed event if necessary
		rfpCaseEvent.createRfpCaseEvent();
		
		EventSummarySubview eventSummarySubview = PageLoader.load(EventSummarySubview.class);
		EventSourceSubview eventSourceSubview = eventSummarySubview.navigateSourcing();
		RfpSetting rfpSetting = eventSourceSubview.clickAddRfp();
		
		// Get max length from page
		UIElement rfpNameInput = IdentifierFactory.createUIElement("RfpSetting", "rfpName");
		logger.info("Rfp name field max length is " + rfpNameInput .getAttribute("maxlength"));
		
		logger.info("Verify the rfp name is over max length");
		String rfpName = RandomString.generateReplicateString(20, "TestForRfpName");
		rfpNameInput.clear();
		rfpNameInput.sendKeys(rfpName);
		RfpBasicsSubview nextPage = rfpSetting.clickNext();
		rfpSetting = (RfpSetting)nextPage.clickPrevious();
		
		rfpNameInput = IdentifierFactory.createUIElement("RfpSetting", "rfpName");
		String actualRfpName = rfpNameInput.getAttribute("value").trim();
		if(actualRfpName.length() != 250){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					RfpName001.class.getName(), 
					"Verify rfp name input max length is 250", 
					"The actual length of rfp name is " + actualRfpName.length()));
		}
		
		eventSourceSubview = rfpSetting.clickCancel();
		eventSourceSubview = eventSourceSubview.checkRfpFromGrid("Draft: " + actualRfpName);
		eventSourceSubview = eventSourceSubview.clickDeleteRfp();
		eventSourceSubview.confirmPopup(true);
		
		loginBusiness.logout();
		FailureAssertion.pop(RfpName001.class);
	}

}
